package com.itmiaojie.runner;

import com.itmiaojie.mapper.ArticleMapper;
import com.itmiaojie.pojo.vo.ViewCount;
import com.itmiaojie.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class LoadViewCount  implements CommandLineRunner {


    @Autowired
    private RedisCache redisCache;
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public void run(String... args) throws Exception {

        System.out.println("我启动了！！！！！！！！！1");
        List<ViewCount> viewCount = articleMapper.selectViewCount();
        for (ViewCount v : viewCount) {
            redisCache.setCacheObject(v.getId().toString(),v.getViewCount());
        }

    }
}
